//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Vml.Drawing
{
    class Rule : IOfficeXmlSerializable
    {
        private string id;
        private RuleType? type;
        private HorizontalRuleAlignment? how;
        private string idref;
        List<Proxy> proxies = new List<Proxy>();

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("r"))
            {
                id = c.GetString("id");

                type = c.GetOptionalEnum<RuleType>("type");
                how = c.GetOptionalEnum<HorizontalRuleAlignment>("how");
                idref = c.GetOptionalString("idref");
                proxies.Clear();
                proxies.AddRange(c.ReadOptionalWhile<Proxy>("proxy"));
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("r"))
            {
                c.SetString("id", id);

                c.SetOptionalEnum<RuleType>("type", type);
                c.SetOptionalEnum<HorizontalRuleAlignment>("how", how);
                c.SetOptionalString("idref", idref);
                c.WriteElements(proxies);
            }
        }
    }
}